<template>
	<view class="" style="padding: 1rpx 30rpx 30rpx;">
		<view class="mainpadding radius ffffff margin_top" v-for="(item,index) in list.data" :key="item.id">
			<view class="flexbetween"  @click="tzpjxq(item.id)">
				<view class="flexleft">
					<image class="touxiag margin_right2" :src="item.user.avatar_text" mode=""></image>
					<view class="">
						<view class="zhonghei sanshier ">{{item.user.nickname}}</view>
						<view class="xiaohui ershil margin_top1 ">{{item.createtime_text}}</view>
					</view>
				</view>
				<u-rate :value="item.star" activeColor="#ff9341" readonly></u-rate>
			</view>
			<view class="xiaohui ershiba margin_top"  @click="tzpjxq(item.id)">{{item.content}}</view>
			<template v-if="item.video_url_text">
				<video class="scyyzz margin_top" :id="'video'+index" :src="item.video_url_text"
					@play.stop="videoplay(index)"></video>
			</template>
			<view class="flexleft flex_wrap pdl">
				<view class="flexcenter tpbox " v-for="(ite,ind) in item.images_text" :key="ind">
					<view class="tjtp">
						<image class="" :src="ite" mode="" @click.stop="lbtpriview(ind,item.images_text)"></image>
					</view>
				</view>
			</view>
			<view class="huibox margin_top mainpadding" v-if="item.reply_content">
				<view class="xiaohui ershiba">商家回复：
					<text class="xiaohei ershiba">{{item.reply_content}}</text>
				</view>
			</view>
			<view class="huibox margin_top mainpadding" v-if="item.zp_content">
				<view class="xiaohui ershiba">追评：
					<text class="xiaohei ershiba">{{item.zp_content}}</text>
				</view>
			</view>
		</view>
	</view>
	
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")

	export default {
		data() {
			return {
				listid: "",
				page: 1,
				list: {
					data: []
				},
				type:1,//1商品，2酒店
			}
		},
		onLoad(options) {
			this.listid = options.id
			this.type = options.type
			this.init()
		},
		methods: {
			videoplay(index) {
				let _this = this;
				//全局变量changePlay表示正在切换。每次切换完播放等一秒在恢复，解决Android下的问题
				if (this.changePlay) {
					return
				}
				_this.changePlay = true
				let currentIndex = 'video' + index; // 获取当前视频索引
				console.log("playVideo currentIndex ", currentIndex)
				// 获取视频列表
				this.list.data.forEach((item, index) => { // 获取json对象并遍历, 停止非当前视频
					if (item.video_url_text) {
						let temp = 'video' + index;
						if (temp != currentIndex) { //判断名字是否一致
							// 暂停其余视频
							console.log(temp, currentIndex, '暂停播放');
							uni.createVideoContext(temp, _this).pause(); //暂停视频播放事件
						}
					}
			
				})
				setTimeout(() => {
					_this.changePlay = false
				}, 1000)
			},
			init(isPage, page) {
				let _this = this
				let data = {
					page: page || 1,
					limit: 12,
					goods_id: this.listid,
				}
				let url = "/api/goodscl/goodsComment"
				if(this.type==2){
					url = "/api/Hotelcl/hotelCommentIndex"
					delete data.goods_id
					this.$set(data,"id",this.listid)
				}
				httpRequest.request(url, 'GET', data).then(res => {
					if (res.code == 1) {
						let resList = res.data;
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data = dataList.data.concat(resList.data);
						} else {
							this.list = res.data
							_this.list.data = resList.data;
						}
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page);
			},
			// 跳转评价详情
			tzpjxq(id) {
				uni.navigateTo({
					url: '/pages_lianmengsc/pingjxq?id='+id
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.huibox {
		background: #F5F5F5;
		border-radius: 11rpx 11rpx 11rpx 11rpx;
	}
	.touxiag {
		width: 73rpx;
		border-radius: 50%;
		height: 73rpx;
	
	}
	.scyyzz {
		width: 100%;
		height: 291rpx;
	}
	
	.tpbox {
		width: 33.33%;
		margin-top: 30rpx;
	}
	
	.tjtp {
		width: 209rpx;
		height: 209rpx;
		position: relative;
	
		image {
			border-radius: 10rpx;
			width: 100%;
			height: 100%;
		}
	}
	.tupian {
		width: 140rpx;
		height: 140rpx;
		border-radius: 18rpx 18rpx 18rpx 18rpx;
	}

	.touxiang {
		width: 73rpx;
		height: 73rpx;
		border-radius: 50%;
	}
</style>